function Chromosome = adaptiveMutation(Chromosome, DSM, allFitnessValues, avgFitness, params)
    % Adaptive mutation based on fitness (Eq 4.4)
    if isempty(Chromosome) || size(Chromosome, 1) <= 1
        return; % Cannot mutate empty or single-module chromosome
    end

    num_modules = size(Chromosome, 1);
    M = params.M;

    % Calculate fitness of the current individual
    fitness = calculateFitness(Chromosome, DSM); % Use the placeholder/real function

    % Calculate max fitness from the provided list
    if isempty(allFitnessValues)
         maxFitness = fitness; % Edge case
    else
         maxFitness = max(allFitnessValues);
         if maxFitness <= avgFitness % Avoid division by zero if all are same
             maxFitness = avgFitness + 1e-6;
         end
    end
    

    % Calculate mutation probability (pm) using Eq 4.4
    if fitness < avgFitness
        pm = params.MutationK1;
    else
        denominator = (maxFitness - avgFitness);
        if denominator < 1e-9; denominator = 1e-9; end % Avoid division by zero
        pm = params.MutationK2 * (maxFitness - fitness) / denominator;
        % Ensure pm is not negative if fitness somehow exceeds maxFitness slightly
        pm = max(0, pm); 
    end
    
    % Apply mutation
    if rand < pm
        % Select a random element (column) to mutate
        col_to_mutate = randi(M);

        % Find its current module
        current_module = find(Chromosome(:, col_to_mutate), 1);
        if isempty(current_module) % Should not happen if chromosome is valid
            warning('Invalid column found during mutation.');
            return; 
        end

        % Select a *different* random module
        new_module = current_module;
        while new_module == current_module
            new_module = randi(num_modules);
        end

        % Perform mutation
        Chromosome(current_module, col_to_mutate) = 0;
        Chromosome(new_module, col_to_mutate) = 1;
    end
end
